package org.lemma.set;

import org.lemma.number.Natural;
import org.lemma.number.Boolean;
import java.io.Serializable;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.annotation.Author;
import javax.annotation.Copyright;
import javax.annotation.Version;

/**
 * <p>
 *  TODO: Javadoc for {@code EmptySet}
 * </p>
 *
 * @author Chris Beatty [christopher.beatty@gmail.com]
 * @param D The object type for the domain
 * @version 1.0.0
 */
@Version (
    major="1", minor="0", patch="0", 
    date="Jun 12, 2008 2:11:28 PM",
    authors = {
        @Author (name="Chris Beatty", email="christopher.beatty@gmail.com")
    }
) @Copyright 
public class EmptySet<D> extends    AbstractSet<D>
                         implements FiniteSet<D, Boolean>,
                                    Serializable {
    
    private static final long serialVersionUID = 1L;

    /**
     * {@inheritDoc}
     *
     * Since the empty set has no elements, this method always returns {@code false}
     *
     * @param arg {@inheritDoc}
     * @return {@inheritDoc}
     */
    @Override
    public Boolean hasMember(D arg) {
        return Boolean.FALSE;
    }

    /**
     * {@inheritDoc}
     * 
     * The cardinality of the empty set is defined to be zero: |&empty;| &equiv; 0
     * 
     * @return {@inheritDoc}
     */
    @Override
    public Natural cardinality() {
        return Natural.ZERO;
    }
    
    /**
     * {@inheritDoc}
     * 
     * @return {@inheritDoc}
     */
    @Override
    public int size() {
        return 0;
    }

    /**
     * {@inheritDoc}
     * 
     * Attempting to add an element to the empty set has no effect
     * 
     * @param e {@inheritDoc}
     * @return Always returns {@code false}
     */
    @Override
    public boolean add(D e) {
        return false;
    }

    /**
     * {@inheritDoc}
     * 
     * Attempting to add an element to the empty set has no effect
     * 
     * @param c {@inheritDoc}
     * @return Always returns {@code false}
     */
    @Override
    public boolean addAll(Collection<? extends D> c) {
        return false;
    }    
    
    /**
     * {@inheritDoc}
     * 
     * @return {@inheritDoc}
     */    
    @Override
    public Iterator<D> iterator() {
        return new Iterator<D>() {

            public boolean hasNext() {
                return false;
            }

            public D next() {
                throw new NoSuchElementException("Iterator Empty");
            }

            public void remove() {
                throw new IllegalStateException("Iterator Empty");
            }
            
        };
    }
    
}
